﻿@model Catalog
@Html.Extra()
@{
    Layout = "~/Views/Shared/OA/_Form.cshtml";

    var isAdmin = ManagerAuthorization.Current.User.IsAdmin;

    if (Model.Type == 0)
    {
        Model.Type = (int)CatalogType.Article;
    }
}
@section Toolbar
{
    @Html.MyNet().Button(new ButtonOptions { Text = "保存", Click = "save" })
    @Html.MyNet().Button(new ButtonOptions { Text = "返回", Click = "back" })
}
@section Main
{
    @Html.HiddenFor(model => model.Id)
    @Html.HiddenFor(model => model.Path)

    @Html.HiddenFor(model => model.Config)

<div class="pop-up-model">
    <div class="img-action-wrap">
        <div class="header">
            <span>编辑图片</span>
        </div>
        <div class="edit-container">
            <div class="pannel">
                <img style="max-width: 100; display: none;" id="image" src="" alt="">
            </div>
            <div class="menu">
                <div class="menu-item">
                    <p> 裁剪尺寸</p>
                    <div class="menu-btn" id="size-btn">
                        <span data-index="1">自定义</span>
                        <span data-index="2">2:1</span>
                        <span data-index="2">3:2</span>
                        <span data-index="3">4:3</span>
                        <span class="active" data-index="4">16:9</span>
                    </div>
                </div>

                <div class="menu-item">
                    <p>底图操作</p>
                    <div class="menu-btn" id="base-img-btn">
                        <span>旋转</span>
                        <span>缩小</span>
                        <span>放大</span>
                        <br/>
                        <span>翻转X轴</span>
                        <span>翻转Y轴</span>
                        <br/>
                        <span>上移</span>
                        <span>下移</span>
                        <span>左移</span>
                        <span>右移</span>
                    </div>
                </div>
                <div class="menu-item">
                    <p>图片操作</p>
                    <div class="menu-btn" id="preview-img-btn">
                        <input id="file-up" style="display: none" type="file">
                        <span>本地上传</span>
                        <span>预览</span>
                        <span>上传封面</span>
                        <span>设置封面</span>
                    </div>
                </div>
                <div class="menu-item"
                     style="position: absolute; bottom: 10px; right: 0;left: 0;">
                    <div class="menu-btn" id="action-img-btn">
                        <span style="background-color: #fff;border-color: #dcdee2;color: #515a6e;">取消</span>
                        <span>保存</span>
                    </div>
                </div>
            </div>
        </div>
        <div class="footer"></div>
    </div>
</div>

    @if (Request["parentKey"] == "xzt")//新专题
    {

        <table>
            @Html.HiddenFor(model => model.ParentId)
            @Html.HiddenFor(model => model.Key)
            @Html.Hidden("Type", (int)CatalogType.Topic)

            <tr>
                <th>
                    @Html.LabelFor(model => model.Name, "名称")
                </th>
                <td>
                    @Html.MyNet().TextBoxFor(model => model.Name, new ValidateOptions
                    {
                        RequiredError = "请输入名称",
                        LengthMax = 64
                    })
                    @Html.MyNet().ValidationMessageFor(model => model.Name)
                </td>
            </tr>

            <tr>
                <th>
                    @Html.LabelFor(model => model.ImageUrl, "列表图片")
                </th>
                <td>
                    <input id="ImageUrl" name="ImageUrl" style="display: none"
                           value="@Html.Raw(Model.BannerUrl)" type="text">

                    <span class="span-btn" id="ImageUrlBtn">上传图片</span>

                    <img id="ImageUrlImg"
                         style="width: 300px; min-height: 200px; margin-top: 10px;background: #f5f5f5"
                         src="@Html.Raw(Model.ImageUrl)" alt="">

                    @*   @Html.MyNet().UploadFor(model => model.ImageUrl, new UploadOptions
                    {
                        AttachmentKey = Model.Id,
                        AttachmentTypeKey = "CMS_CatalogImage",
                        UploadMode = UploadMode.ImageSingle,
                        PreviewImageWidth = 300
                    }) *@
                </td>
            </tr>
            <tr>
                <th>
                    @Html.LabelFor(model => model.BannerUrl, "导航图片")
                </th>
                <td>

                    <input id="BannerUrl" name="BannerUrl" style="display: none"
                           value="@Html.Raw(Model.BannerUrl)" type="text">

                    <span class="span-btn" id="BannerUrlBtn">上传图片</span>

                    <img id="BannerUrlImg"
                         style="width: 600px; min-height: 100px; margin-top: 10px;background: #f5f5f5"
                         src="@Html.Raw(Model.BannerUrl)" alt="">

                 @*   @Html.MyNet().UploadFor(model => model.BannerUrl, new UploadOptions
                    {
                        AttachmentKey = Model.Id,
                        AttachmentTypeKey = "CMS_CatalogBannerImage",
                        UploadMode = UploadMode.ImageSingle,
                        PreviewImageWidth = 600
                    }) *@
                </td>
            </tr>
            <tr>
                <th>
                    @Html.LabelFor(model => model.Description, "描述")
                </th>
                <td>
                    @Html.MyNet().TextAreaFor(model => model.Description, new ValidateOptions
                    {
                        LengthError = "不能超过256字符",
                        LengthMax = 256
                    })
                    @Html.MyNet().ValidationMessageFor(model => model.Description)
                </td>
            </tr>
            <tr>
                <th></th>
                <td>
                    @Html.CheckBoxFor(model => model.IsEnable)
                    @Html.LabelFor(model => model.IsEnable, "是否启用")
                </td>
            </tr>
            @if (isAdmin)
            {
                @Html.HiddenFor(model => model.SortIndex)
            }
            else
            {
                <tr>
                    <th>排序</th>
                    <td>
                        @Html.MyNet().TextBoxFor(model => model.SortIndex)
                    </td>
                </tr>
            }
        </table>
    }
    else
    {
        <fieldset>
            <legend>基本设置</legend>
            <table>

                @if (isAdmin)
                {
                    <tr>
                        <th>
                            @Html.LabelFor(model => model.ParentId, "父级")
                        </th>
                        <td>
                            @Html.MyNet().DropDownTreeFor(model => model.ParentId, Url.Action("Read"))
                        </td>
                    </tr>
                }
                else
                {
                    @Html.HiddenFor(model => model.ParentId)
                }

                <tr>
                    <th>
                        @Html.LabelFor(model => model.Name, "名称")
                    </th>
                    <td>
                        @Html.MyNet().TextBoxFor(model => model.Name, new ValidateOptions
                        {
                            RequiredError = "请输入名称",
                            LengthMax = 64
                        })
                        @Html.MyNet().ValidationMessageFor(model => model.Name)
                    </td>
                </tr>
                <tr>
                    <th>
                        @Html.LabelFor(model => model.Key, "代码")
                    </th>
                    <td>
                        @Html.MyNet().TextBoxFor(model => model.Key, new ValidateOptions
                        {
                            RequiredError = "请输入代码",
                            LengthMax = 64
                        })
                        @Html.MyNet().ValidationMessageFor(model => model.Key)
                    </td>
                </tr>
                @if (isAdmin)
                {

                    <tr>
                        <th>
                            @Html.LabelFor(model => model.Type, "类型")
                        </th>
                        <td>
                            @Html.MyNet().DropDownListFor(model => model.Type, new[]
                                                                                                                                                                                    {
                                                                    new { Value = (int)CatalogType.Article, Name = CatalogType.Article.ToText() },
                                                                    new { Value = (int)CatalogType.ArticleDetail, Name = CatalogType.ArticleDetail.ToText() },
                                                                    new { Value = (int)CatalogType.Image, Name = CatalogType.Image.ToText() },
                                                                    new { Value = (int)CatalogType.Advertisement, Name = CatalogType.Advertisement.ToText() },
                                                                    new { Value = (int)CatalogType.FriendshipLink, Name = CatalogType.FriendshipLink.ToText() },
                                                                     new { Value = (int)CatalogType.QPH, Name = CatalogType.QPH.ToText() },
                                                                      new { Value = (int)CatalogType.Topic, Name = CatalogType.Topic.ToText() },
                                                                    //new { Value = (int)CatalogType.Vote, Name = CatalogType.Vote.ToText() },
                                                                    //new { Value = (int)CatalogType.Other, Name = CatalogType.Other.ToText()}
                                                                    }, "Value", "Name", "请选择类型", new ValidateOptions
                                                                    {
                                                                        RequiredError = "请选择类型"
                                                                    })
                            @Html.MyNet().ValidationMessageFor(model => model.Type)
                        </td>
                    </tr>
                }
                else
                {
                    @Html.HiddenFor(model => model.Type)
                }
                <tr>
                    <th>
                        @Html.LabelFor(model => model.ImageUrl, "图片")
                    </th>
                    <td>

                        <input id="ImageUrl" name="ImageUrl" style="display: none"
                               value="@Html.Raw(Model.BannerUrl)" type="text">

                        <span class="span-btn" id="ImageUrlBtn">上传图片</span>

                        <img id="ImageUrlImg"
                             style="width: 600px; min-height: 100px; margin-top: 10px;background: #f5f5f5"
                             src="@Html.Raw(Model.ImageUrl)" alt="">
                        @*   @Html.MyNet().UploadFor(model => model.ImageUrl, new UploadOptions
                        {
                            AttachmentKey = Model.Id,
                            AttachmentTypeKey = "CMS_CatalogImage",
                            UploadMode = UploadMode.ImageSingle,
                            PreviewImageWidth = 300
                        }) *@
                    </td>
                </tr>
                <tr>
                    <th>
                        @Html.LabelFor(model => model.BannerUrl, "导航图片")
                    </th>
                    <td>
                        <input id="BannerUrl" name="BannerUrl" style="display: none"
                               value="@Html.Raw(Model.BannerUrl)" type="text">

                        <span class="span-btn" id="BannerUrlBtn">上传图片</span>

                        <img id="BannerUrlImg"
                             style="width: 600px; min-height: 100px; margin-top: 10px;background: #f5f5f5"
                             src="@Html.Raw(Model.BannerUrl)" alt="">

                        @* @Html.MyNet().UploadFor(model => model.BannerUrl, new UploadOptions
                        {
                            AttachmentKey = Model.Id,
                            AttachmentTypeKey = "CMS_CatalogBannerImage",
                            UploadMode = UploadMode.ImageSingle,
                            PreviewImageWidth = 600
                        })  *@
                    </td>
                </tr>

                <tr>
                    <th>
                        @Html.LabelFor(model => model.Keyword, "关键字")
                    </th>
                    <td>
                        @Html.MyNet().TextAreaFor(model => model.Keyword, new ValidateOptions
                        {
                            LengthError = "不能超过256字符",
                            LengthMax = 256
                        })
                        @Html.MyNet().ValidationMessageFor(model => model.Description)
                    </td>
                </tr>
                <tr>
                    <th>
                        @Html.LabelFor(model => model.Description, "描述")
                    </th>
                    <td>
                        @Html.MyNet().TextAreaFor(model => model.Description, new ValidateOptions
                        {
                            LengthError = "不能超过256字符",
                            LengthMax = 256
                        })
                        @Html.MyNet().ValidationMessageFor(model => model.Description)
                    </td>
                </tr>
                <tr>
                    <th></th>
                    <td>
                        @Html.CheckBoxFor(model => model.IsEnable)
                        @Html.LabelFor(model => model.IsEnable, "是否启用")
                    </td>
                </tr>
                @if (isAdmin)
                {
                    @Html.HiddenFor(model => model.SortIndex)
                }
                else
                {
                    <tr>
                        <th>排序</th>
                        <td>
                            @Html.MyNet().TextBoxFor(model => model.SortIndex)
                        </td>
                    </tr>
                }
            </table>
        </fieldset>

        <fieldset>
            <legend>导航设置</legend>
            <table>
                <tr>
                    <th>
                        @Html.LabelFor(model => model.LinkUrl, "导航地址")
                    </th>
                    <td>
                        @Html.MyNet().TextBoxFor(model => model.LinkUrl)
                    </td>
                </tr>
                <tr>
                    <th></th>
                    <td>
                        @Html.MyNet().CheckBoxFor(model => model.IsNav)
                        @Html.LabelFor(model => model.IsNav, "是否导航")
                    </td>
                </tr>
            </table>
        </fieldset>
        if (isAdmin)
        {
            <fieldset>
                <legend>汽派号设置</legend>
                <table>
                    <tr>
                        <th>
                        </th>
                        <td>
                            @Html.MyNet().CheckBoxFor(model => model.IsQPH)
                            @Html.LabelFor(model => model.IsQPH, "是否汽派号")
                        </td>
                    </tr>
                </table>
            </fieldset>
        }
        else
        {
            @Html.HiddenFor(model => model.IsQPH)
        }
    }
}
<script type="text/javascript" src="~/App_Content/Script/OA/cropper.min.js"></script>
<script type="text/javascript" src="~/App_Content/Script/OA/ajax.js"></script>
<script type="text/javascript" src="~/App_Content/Script/OA/libs.js"></script>
<script type="text/javascript" src="~/App_Content/Script/OA/img-action.js"></script>
<script>


  upBtn('BannerUrl');
  upBtn('ImageUrl');
    function save() {
        var form = $("form");
        if (!form.valid()) return;

        $.ajax
            ({
                url: form.attr("action"),
                data: form.serialize(),
                type: "post",
                error: disposeError,
                success: function (result) {
                    if (disposeException(result)) return;
                    var data = { id: result.Id, text: result.Name, parentId: result.ParentId };
                    back(true, data);
                }
            });
    }

</script>
